<?php

namespace app\api\model\shop;


use addons\epay\library\Service;
use app\admin\model\User;
use app\api\model\Qrcode;

use app\shopapi\model\ShopGoods;
use think\Db;
use think\Model;
use traits\model\SoftDelete;
use think\Cache;
use Yansongda\Pay\Exceptions\GatewayException;

class ShopFans extends Model
{
    protected $name = 'shop_fans';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;


    public static function add($user_id,$shop_id)
    {
        $info = \app\shopapi\model\ShopFans::where(['user_id'=>$user_id])->find();
        $user = User::get($user_id);
        if (!$info&&!$user->parent_id){
            $shop_fans_model = new ShopFans();
            $shop_fans_data = [
                'user_id'=>$user_id,
                'shop_id'=>$shop_id,
            ];
            $res = $shop_fans_model->save($shop_fans_data);
            Shop::where(['shop_id'=>$shop_id])->setInc('fans_num');
        }

        return true;
    }
}